<template>
  <div>
    <!-- picker选择器 -->
    <van-picker
      title="编辑性别"
      show-toolbar
      :columns="columns"
      :default-index="userInfo.gender"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import { editUser } from '@/api/user'
export default {
  name: 'updateGender',
  props: {
    userInfo: {
      required: true
    }
  },

  data () {
    return {
      columns: ['男', '女']
    }
  },

  mounted () {},

  methods: {
    async onConfirm (v, i) {
      try {
        await editUser({ gender: i })
        this.$toast.success('修改成功')
        this.$emit('closePop', false)
        // 修改父组件的名字
        // eslint-disable-next-line vue/no-mutating-props
        this.userInfo.gender = i
      } catch (error) {
        this.$toast.fail('修改失败')
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
